

using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.Threading;
using Microsoft.Xna.Framework.Input;
using System;
namespace RaceGame2013
{
    public class Menu

    {


        //menu choice constructor
        private Texture2D StartGameButton;
        private Texture2D ExitButton;
        private Texture2D ShowGamePlayButton;
        private Texture2D SinglePlayerButton;
        private Texture2D MultiPlayerButton;
        private Texture2D SelectCarButton;
        private Texture2D SelectTrackButton;

        private Vector2 ShowGamePlayButtonPosition;
        private Vector2 StartGameButtonPosition;
        private Vector2 ExitButtonPosition;
        private Vector2 SinglePlayerButtonPosition;
        private Vector2 MultiplayerButtonposition;
        private Vector2 SelectTrackButtonposition;
        private Vector2 SelectCarButtonPosition;

        //menu backgroundthread + mouse position
        private Thread backgroundThread;
        MouseState mouseState;
        MouseState previousMouseState;
        Boolean IsMouseVisible; 

        public enum GameState
        {
            StartMenu,
            ShowGamePlay,
            SelectTrack,
            SelectCar,
        }
        public GameState gameState = GameState.StartMenu;

        private int menuChoice;

        ContentManager Content;
        SpriteBatch spriteBatch;
        GraphicsDeviceManager graphics;
        GraphicsDevice graphicsDevice;
        
        public Menu(ContentManager content, GraphicsDeviceManager graphics, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
        {
            this.Content = content;
            this.graphics = graphics;
            this.spriteBatch = spriteBatch;
            this.graphicsDevice = graphicsDevice;

            //enable the mousepointer
            IsMouseVisible = true;

            //set the gamestate to start menu
            gameState = GameState.StartMenu;


            // position of the Button menuchoice
            StartGameButtonPosition = new Vector2((graphicsDevice.Viewport.Width / 2) - 50, 200);
            ExitButtonPosition = new Vector2((graphicsDevice.Viewport.Width / 2) - 50, 250);

            //get the mouse state
            mouseState = Mouse.GetState();
            previousMouseState = mouseState;

        }

        public void LoadContent()
        {
            //load the buttonimages into the content pipeline
            StartGameButton = Content.Load<Texture2D>(@"Buttons/startGame");
            ExitButton = Content.Load<Texture2D>(@"Buttons/exit");
            MultiPlayerButton = Content.Load<Texture2D>(@"Buttons/multiplay");
            //SelectCarButton = Content.Load<Texture2D>(@"Buttons/selectcar");
            SinglePlayerButton = Content.Load<Texture2D>(@"Buttons/single player");
            SelectTrackButton = Content.Load<Texture2D>(@"Buttons/select Track");
            //stopButton = Content.Load<Texture2D>(@"stop");
        }

        
        public void Update()
        {
            //wait for mouseclick
            mouseState = Mouse.GetState();
            if (previousMouseState.LeftButton == ButtonState.Pressed && mouseState.LeftButton == ButtonState.Released)
            {
                MouseClicked(mouseState.X, mouseState.Y);
            }


        }


        public void Draw()
        {
            // StartMenu Page
            if (gameState == GameState.StartMenu)
            {
                spriteBatch.Draw(StartGameButton, StartGameButtonPosition, Color.White);
                spriteBatch.Draw(ExitButton, ExitButtonPosition, Color.White);
                //spriteBatch.Draw(optionButton, optionButtonPosition, Color.White);
            }

        }

       public void MouseClicked(int x, int y)
        {
            //creates a rectangle of 10x10 around the place where the mouse was clicked
            Rectangle mouseClickRect = new Rectangle(x, y, 10, 10);

            //check the startmenu
            if (gameState == GameState.StartMenu)
            {
                Rectangle StartGameButtonRect = new Rectangle((int)StartGameButtonPosition.X,
                                        (int)StartGameButtonPosition.Y, 100, 20);
                Rectangle ExitButtonRect = new Rectangle((int)ExitButtonPosition.X,
                                    (int)ExitButtonPosition.Y, 100, 20);

                if (mouseClickRect.Intersects(StartGameButtonRect)) //player clicked start button
                {
                    gameState = GameState.ShowGamePlay;
                    
                }
                else if (mouseClickRect.Intersects(ExitButtonRect)) //player clicked exit button
                {
                    Exit();
                }
            }
        }



        public void ShowGamePlay()
        {

            gameState = GameState.ShowGamePlay;
        }

        public void SelectPlayer()
        {

        }

        public void StartGame()
        {

        }

        public void Exit()
        {
           
        }

        public void SelectCar()
        {

        }
    }
}